package com.javaweb.controller;

/**
 * @desc:
 * @author: Ping
 * @date: 2024/10/30 11:31
 */

import com.javaweb.controller.common.ResponseResult;
import com.javaweb.service.UserService;
import com.javaweb.service.dto.UserConditionDto;
import com.javaweb.service.dto.UserDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * todo: 实现用户登录
 *
 */
@RestController
@RequestMapping("/blog-api/v0.1/user")
public class UserController {

    @Autowired
    private UserService userService;


    @PostMapping("/list")
    public ResponseResult<List<UserDto>> getList(@RequestBody UserConditionDto userConditionDto){
        return ResponseResult.ok(userService.list(userConditionDto));
    }

    @PostMapping("/add")
    public ResponseResult addUser(@RequestBody UserDto userDto){

        return ResponseResult.ok(userService.add(userDto),"添加成功");
    }

    @PostMapping("/password/change")
    public ResponseResult changePassword(Integer userId, String newPassword){
        return ResponseResult.ok(userService.changePassword(userId,newPassword),"修改成功");
    }

}
